package com.zuorenke.help;

import com.zuorenke.model.Result;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.http.HttpServerResponse;

/**
 * @author Z.R.K
 * @description
 * @create 2019-05-20 15:27:58
 **/
public class ResponseUtils {
	private ResponseUtils() {
	}
	
	public static void responseResult(HttpServerResponse response, Result result) {
		response.putHeader("content-type", "application/json; charset=utf-8")
				.setStatusCode(200).end(result.toString());
	}
	
	public static void response500Msg(HttpServerResponse response, String msg) {
		response.putHeader("content-type", "application/json; charset=utf-8")
				.setStatusCode(200).end("{\"code\":500,\"msg\":\"" + msg + "\"}");
	}
	
	public static void responseErrorMsg(HttpServerResponse response, HttpResponseStatus status) {
		Result result = new Result();
		result.setSuccess(false);
		result.setCode(status.code());
		result.setMsg(status.reasonPhrase());
		responseResult(response, result);
	}
}
